/**
 * Note: We break up object encapsulation principle for easy to test.
 */
class ExtractServiceTests extends GroovyTestCase {

    def extractService

    void testDependencyInjection() {
        assertNotNull("extractService should be automatic inject", extractService)
        assertNotNull("TaskExecutor in extractService should not be null too", extractService.taskExecutor)
        assertNotNull("BeanFactory in ExtractService should be set  by BeanFactoryAware ", extractService.beanFactory)
    }

    void testBeanScope() {
        def p1 = extractService.beanFactory.getBean("extractProcess")
        def p2 = extractService.beanFactory.getBean("extractProcess")
        assertTrue("extractProcess must be config to be a prototype scope", p1 != p2)

        def p3 = extractService.beanFactory.getBean("extractService")
        assertTrue("extractService must be singleton scope", extractService == p3)
    }

    void testTaskExecutor() {
        def f1 = false
        def f2 = false
        extractService.taskExecutor.execute({ f1 = true } as Runnable)
        extractService.taskExecutor.execute({ f2 = true } as Runnable)
        Thread.sleep(1)
        assertTrue(f1 && f2)
    }
    

}
